class_name Spinner
extends MarginContainer

const SPINNER_RATE = 0.5  # Fraction of a rotation per second


func _ready() -> void:
	connect("visibility_changed", self, "_on_visibility_changed")


func _process(delta: float) -> void:
	var current_rotation: float = $TextureRect.get_rotation()
	var new_rotation: float = fmod(
		current_rotation + 2.0 * PI * SPINNER_RATE * delta,
		2.0 * PI
	)
	$TextureRect.set_rotation(new_rotation)


func _on_visibility_changed() -> void:
	set_process(self.visible)
